//
//  AppDelegate.swift
//  NewsItem
//
//  Created by mac on 2023/6/27.
//

import UIKit
import Kingfisher
import AdSupport
import AppTrackingTransparency
import Alamofire
@_exported import Stevia

@main
class AppDelegate: UIResponder, UIApplicationDelegate,UNUserNotificationCenterDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        IQKeyboardManager.shared().isEnabled = true
        UNUserNotificationCenter.current().delegate = self
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
            if error == nil {
                debugPrint("REGISTRATION NOTIFICATION SUCCESSED")
            }else {
                debugPrint("REGISTRATION NOTIFICATION FAILURE")
            }
        }
        application.registerForRemoteNotifications()
        if UserDefaults.standard.object(forKey: "UserInfo") != nil{
            let str = GetInfo(key: "UserInfo") as! NSDictionary
            let jsonData = InfoUtil.initInfo.deserialize(from: str)
            USEINFOMODEL = jsonData!
            let vc = Pet_TabbarViewController()
            self.window?.rootViewController = vc
        }else
        {
            let vc = Pet_LoginHomeViewController()
            self.window?.rootViewController = NavigationInterface(rootViewController: vc)
        }
        self.window?.makeKeyAndVisible()
        return true
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
            DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: {
                if #available(iOS 14, *) {
                    ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
                    })
                }
            })
     }
}

